
window.onload = function(){

    // 延时加载动画一
    setTimeout(function(){
        $(".item1 .text-wrap").addClass('fadeInDown');
    },1000);

    //  导航二维码
    $('.top-download').mouseenter(function(){
        setTimeout(function(){
            $('.down-erweima').removeClass('hidden');
        }, 10);
    });
    $('.top-download').mouseleave(function(){
        setTimeout(function(){
            $('.down-erweima').addClass('hidden');
        }, 100);
    });

    // 资讯页

    $.ajax({
        url: "http://51son.net:8088/api/information/pcLabellist",
        type: "POST",
        async: false,
        success:function(data){
            var bannerdata = data.data.bannerList;
            for (x = 0; x <bannerdata.length; x++) {
                var swiper = $('<div>').addClass('swiper-slide');
                var link = bannerdata[x].link;
                var href = 'Information-detail.html' + '#' + link; 
                var banner_left = $('<div>').addClass('banner-left fl');
                var banner_img = $('<a>').attr('href', href).attr('target', '_blank').append($('<img>').attr('src', bannerdata[x].img));

                var banner_txt = $('<div>').addClass('banner-txt fl');

                var titleTxTs;
                var infoContent = bannerdata[x].content;
                $.ajax({
                    url: 'http://51son.net:8088/api/information/detail',
                    type: 'POST',
                    data: {
                        informationId: link
                    },
                    async:false,
                    success:function(message){
                        var informationDetail = message.data.information;
                        var infoTitle = informationDetail.title;
                        if( infoTitle.length > 23 ){
                            titleTxTs = infoTitle.substr(0,23) + "....";
                        }else{
                            titleTxTs = infoTitle;
                        }
                    }
                });

                var h3 = $('<a>').attr('href', href).attr('target', '_blank').append($('<h3>').append(titleTxTs));
                var dec = infoContent.replace(/<p([^<>]*)>([^<>]*)<\/p>/gi, "$2").substr(0,60) + ".....";
                banner_left.append(banner_img);
                banner_txt.append(h3).append(dec);
                swiper.append(banner_left).append(banner_txt);
                $('.swiper-wrapper').append(swiper);
            }
        }
    });
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true
    });

    $.ajax({
        url: "http://51son.net:8088/api/information/labellist",
        type: "POST",
        async: false,
        success:function(result){
            var labelData = result.data.labelList;
            for (i = 0; i < labelData.length; i++) {
                var li = $('<li>').append($('<a>').attr("href", '#' + labelData[i].uuid).attr("role", "tab").attr("data-toggle", "tab").append(labelData[i].content));
                $(".info-nav").append(li);
                $(".info-nav li").eq(0).addClass('active');
                $.ajax({
                    url: "http://51son.net:8088/api/information/list",
                    data: {
                        labelId: labelData[i].uuid,
                        size: 8,
                    },
                    type: "POST",
                    async: false,
                    success:function(msg){
                        var infoData = msg.data.rows;
                        var tabpanel = $('<div>').attr('role', "tabpanel").addClass('tab-pane').attr('id', labelData[i].uuid).attr('data-page', msg.data.page);
                        var ul = $('<ul>').addClass('clearfix');
                        for (o = 0; o < infoData.length; o++){
                            var thumbnailImgs = eval(infoData[o].thumbnailImg);
                            var li = $('<li>');
                            var a = $('<a>').addClass('thumbnailImg').attr('href', 'Information-detail.html' + '#' + infoData[o].informationId).attr('target', '_blank');
                            var img = $('<img>').addClass('img-responsive center-block').attr('src', thumbnailImgs[0].img);
                            a.append(img);
                            if (infoData[o].type == 1) {
                                var video = $('<div>').addClass('videoMask');
                                var videoIcon = $('<div>').addClass('videoIcon');
                                a.append(videoIcon).append(video);
                            }
                            if( infoData[o].title.length > 20 ){
                                if ( document.body.clientWidth < 720 ) {
                                    var titleTxT = infoData[o].title.substr(0,16) + "....";
                                }else{
                                    var titleTxT = infoData[o].title.substr(0,22) + "....";
                                }
                                
                            }else{
                                var titleTxT = infoData[o].title;
                            }
                            var title = $('<a>').addClass('title').attr('href', 'Information-detail.html').attr('target', '_blank').append(titleTxT);

                            var access = $('<div>').addClass('access');
                            var likeMath = $('<span>').append(infoData[o].thumb);
                            var publishTime = infoData[o].publishTime.split(" ");
                            var time = $('<em>').append(publishTime[0]);

                            access.append(likeMath).append(time);
                            li.append(a).append(title).append(access);
                            ul.append(li);
                        }
                        var page = $('<div>').addClass('M-box').addClass('pagination' + i);
                        tabpanel.append(ul).append(page);
                        $(".tab-content").append(tabpanel);
                        $(".tab-content .tab-pane").eq(0).addClass('active');
                    }
                });
            }
            
        }
    });


    // pagination
    $('.pagination0').pagination({
        pageCount: $('.pagination0').parent().attr("data-page"),
        callback:function(api){
            var test = api;
            var current = api.getCurrent();
            $.ajax({
                url: 'http://51son.net:8088/api/information/list',
                data: {
                    labelId: $('.pagination0').parent().attr("id"),
                    current: current,
                    size: 8
                },
                type: 'POST',
                async: false,
                success:function(result){
                    $('.pagination0').siblings('ul').remove();
                    var infoData = result.data.rows;
                    var ul = $('<ul>').addClass('clearfix');
                    for (o = 0; o < infoData.length; o++){
                        var thumbnailImgs = eval(infoData[o].thumbnailImg);
                        var li = $('<li>');
                        var a = $('<a>').addClass('thumbnailImg').attr('href', 'Information-detail.html' + '#' + infoData[o].informationId).attr('target', '_blank');
                        var img = $('<img>').addClass('img-responsive center-block').attr('src', thumbnailImgs[0].img);
                        a.append(img);
                        if (infoData[o].type == 1) {
                            var video = $('<div>').addClass('videoMask');
                            var videoIcon = $('<div>').addClass('videoIcon');
                            a.append(videoIcon).append(video);
                        }
                        if( infoData[o].title.length > 20 ){
                            var titleTxT = infoData[o].title.substr(0,22) + "....";
                        }else{
                            var titleTxT = infoData[o].title;
                        }
                        var title = $('<a>').addClass('title').attr('href', 'Information-detail.html').attr('target', '_blank').append(titleTxT);

                        var access = $('<div>').addClass('access');
                        var likeMath = $('<span>').append(infoData[o].thumb);
                        var publishTime = infoData[o].publishTime.split(" ");
                        var time = $('<em>').append(publishTime[0]);

                        access.append(likeMath).append(time);
                        li.append(a).append(title).append(access);
                        ul.append(li);
                        
                    }
                    $('.pagination0').parent().prepend(ul);
                }
            });
        }
    });

    $('.pagination1').pagination({
        pageCount: $('.pagination1').parent().attr("data-page"),
        callback:function(api){
            var test = api;
            var current = api.getCurrent();
            $.ajax({
                url: 'http://51son.net:8088/api/information/list',
                data: {
                    labelId: $('.pagination1').parent().attr("id"),
                    current: current,
                    size: 8
                },
                type: 'POST',
                async: false,
                success:function(result){
                    $('.pagination1').siblings('ul').remove();
                    var infoData = result.data.rows;
                    var ul = $('<ul>').addClass('clearfix');
                    for (o = 0; o < infoData.length; o++){
                        var thumbnailImgs = eval(infoData[o].thumbnailImg);
                        var li = $('<li>');
                        var a = $('<a>').addClass('thumbnailImg').attr('href', 'Information-detail.html' + '#' + infoData[o].informationId).attr('target', '_blank');
                        var img = $('<img>').addClass('img-responsive center-block').attr('src', thumbnailImgs[0].img);
                        a.append(img);
                        if (infoData[o].type == 1) {
                            var video = $('<div>').addClass('videoMask');
                            var videoIcon = $('<div>').addClass('videoIcon');
                            a.append(videoIcon).append(video);
                        }
                        if( infoData[o].title.length > 20 ){
                            var titleTxT = infoData[o].title.substr(0,22) + "....";
                        }else{
                            var titleTxT = infoData[o].title;
                        }
                        var title = $('<a>').addClass('title').attr('href', 'Information-detail.html').attr('target', '_blank').append(titleTxT);

                        var access = $('<div>').addClass('access');
                        var likeMath = $('<span>').append(infoData[o].thumb);
                        var publishTime = infoData[o].publishTime.split(" ");
                        var time = $('<em>').append(publishTime[0]);

                        access.append(likeMath).append(time);
                        li.append(a).append(title).append(access);
                        ul.append(li);
                        
                    }
                    $('.pagination1').parent().prepend(ul);
                }
            });
        }
    });

    $('.pagination2').pagination({
        pageCount: $('.pagination2').parent().attr("data-page"),
        callback:function(api){
            var test = api;
            var current = api.getCurrent();
            $.ajax({
                url: 'http://51son.net:8088/api/information/list',
                data: {
                    labelId: $('.pagination2').parent().attr("id"),
                    current: current,
                    size: 8
                },
                type: 'POST',
                async: false,
                success:function(result){
                    $('.pagination2').siblings('ul').remove();
                    var infoData = result.data.rows;
                    var ul = $('<ul>').addClass('clearfix');
                    for (o = 0; o < infoData.length; o++){
                        var thumbnailImgs = eval(infoData[o].thumbnailImg);
                        var li = $('<li>');
                        var a = $('<a>').addClass('thumbnailImg').attr('href', 'Information-detail.html' + '#' + infoData[o].informationId).attr('target', '_blank');
                        var img = $('<img>').addClass('img-responsive center-block').attr('src', thumbnailImgs[0].img);
                        a.append(img);
                        if (infoData[o].type == 1) {
                            var video = $('<div>').addClass('videoMask');
                            var videoIcon = $('<div>').addClass('videoIcon');
                            a.append(videoIcon).append(video);
                        }
                        if( infoData[o].title.length > 20 ){
                            var titleTxT = infoData[o].title.substr(0,22) + "....";
                        }else{
                            var titleTxT = infoData[o].title;
                        }
                        var title = $('<a>').addClass('title').attr('href', 'Information-detail.html').attr('target', '_blank').append(titleTxT);

                        var access = $('<div>').addClass('access');
                        var likeMath = $('<span>').append(infoData[o].thumb);
                        var publishTime = infoData[o].publishTime.split(" ");
                        var time = $('<em>').append(publishTime[0]);

                        access.append(likeMath).append(time);
                        li.append(a).append(title).append(access);
                        ul.append(li);
                        
                    }
                    $('.pagination2').parent().prepend(ul);
                }
            });
        }
    });

    $('.pagination3').pagination({
        pageCount: $('.pagination3').parent().attr("data-page"),
        callback:function(api){
            var test = api;
            var current = api.getCurrent();
            $.ajax({
                url: 'http://51son.net:8088/api/information/list',
                data: {
                    labelId: $('.pagination3').parent().attr("id"),
                    current: current,
                    size: 8
                },
                type: 'POST',
                async: false,
                success:function(result){
                    $('.pagination3').siblings('ul').remove();
                    var infoData = result.data.rows;
                    var ul = $('<ul>').addClass('clearfix');
                    for (o = 0; o < infoData.length; o++){
                        var thumbnailImgs = eval(infoData[o].thumbnailImg);
                        var li = $('<li>');
                        var a = $('<a>').addClass('thumbnailImg').attr('href', 'Information-detail.html' + '#' + infoData[o].informationId).attr('target', '_blank');
                        var img = $('<img>').addClass('img-responsive center-block').attr('src', thumbnailImgs[0].img);
                        a.append(img);
                        if (infoData[o].type == 1) {
                            var video = $('<div>').addClass('videoMask');
                            var videoIcon = $('<div>').addClass('videoIcon');
                            a.append(videoIcon).append(video);
                        }
                        if( infoData[o].title.length > 20 ){
                            var titleTxT = infoData[o].title.substr(0,22) + "....";
                        }else{
                            var titleTxT = infoData[o].title;
                        }
                        var title = $('<a>').addClass('title').attr('href', 'Information-detail.html').attr('target', '_blank').append(titleTxT);

                        var access = $('<div>').addClass('access');
                        var likeMath = $('<span>').append(infoData[o].thumb);
                        var publishTime = infoData[o].publishTime.split(" ");
                        var time = $('<em>').append(publishTime[0]);

                        access.append(likeMath).append(time);
                        li.append(a).append(title).append(access);
                        ul.append(li);
                        
                    }
                    $('.pagination3').parent().prepend(ul);
                }
            });
        }
    });

    $('.pagination4').pagination({
        pageCount: $('.pagination4').parent().attr("data-page"),
        callback:function(api){
            var test = api;
            var current = api.getCurrent();
            $.ajax({
                url: 'http://51son.net:8088/api/information/list',
                data: {
                    labelId: $('.pagination4').parent().attr("id"),
                    current: current,
                    size: 8
                },
                type: 'POST',
                async: false,
                success:function(result){
                    $('.pagination4').siblings('ul').remove();
                    var infoData = result.data.rows;
                    var ul = $('<ul>').addClass('clearfix');
                    for (o = 0; o < infoData.length; o++){
                        var thumbnailImgs = eval(infoData[o].thumbnailImg);
                        var li = $('<li>');
                        var a = $('<a>').addClass('thumbnailImg').attr('href', 'Information-detail.html' + '#' + infoData[o].informationId).attr('target', '_blank');
                        var img = $('<img>').addClass('img-responsive center-block').attr('src', thumbnailImgs[0].img);
                        a.append(img);
                        if (infoData[o].type == 1) {
                            var video = $('<div>').addClass('videoMask');
                            var videoIcon = $('<div>').addClass('videoIcon');
                            a.append(videoIcon).append(video);
                        }
                        if( infoData[o].title.length > 20 ){
                            var titleTxT = infoData[o].title.substr(0,22) + "....";
                        }else{
                            var titleTxT = infoData[o].title;
                        }
                        var title = $('<a>').addClass('title').attr('href', 'Information-detail.html').attr('target', '_blank').append(titleTxT);

                        var access = $('<div>').addClass('access');
                        var likeMath = $('<span>').append(infoData[o].thumb);
                        var publishTime = infoData[o].publishTime.split(" ");
                        var time = $('<em>').append(publishTime[0]);

                        access.append(likeMath).append(time);
                        li.append(a).append(title).append(access);
                        ul.append(li);
                        
                    }
                    $('.pagination4').parent().prepend(ul);
                }
            });
        }
    });

}